//import CryptoJS from "./cryptoJs";
import CryptoJS from "crypto-js";
//秘钥
const CRYPTOJSKEY = "qwe!@#456&*(0-==";
export const encryption = {
  // 加密
  encrypt: function(plaintText) {
    var iv = CryptoJS.enc.Utf8.parse("16-Bytes--String");
    var options = {
      iv: iv,
      mode: CryptoJS.mode.ECB,
      padding: CryptoJS.pad.Pkcs7
    };
    var key = CryptoJS.enc.Utf8.parse(CRYPTOJSKEY);
    var encryptedData = CryptoJS.AES.encrypt(plaintText, key, options);
    var encryptedBase64Str = encryptedData.toString();
    return encryptedBase64Str;
  },
  //解密
  decrypt: function(encryptedBase64Str) {
    var vals = encryptedBase64Str;
    var options = {
      mode: CryptoJS.mode.ECB,
      padding: CryptoJS.pad.Pkcs7
    };
    var key = CryptoJS.enc.Utf8.parse(CRYPTOJSKEY);
    var decryptedData = CryptoJS.AES.decrypt(vals, key, options);
    var decryptedStr = CryptoJS.enc.Utf8.stringify(decryptedData);
    return decryptedStr;
  }
};
